package com.leyou.order.web;

import com.leyou.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.MediaType;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("notify")
@Slf4j
public class NotifyController {

    @Autowired
    private OrderService orderService;

    /**
     * 微信支付成功回调
     *
     * @param msg
     * @return
     */
    @PostMapping(value = "wxpay", produces = "application/xml")
    public Map<String, String> payNotify(@RequestBody Map<String, String> msg) {
        // 处理回调
        orderService.handleNotify(msg);

        log.info("[支付回调] 接收微信支付回调, 结果: {}", msg);

        // 返回成功
        Map<String, String> result = new HashMap<>();
        result.put("return_code", "SUCCESS");
        result.put("return_msg", "OK");
        return result;

    }
}
